package my.design.decorator;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author zp
 * @version 1.0
 * @description: 未使用装饰器模式的代码
 * @date 2022/10/10 18:42
 */
public class LoginSsoDecorator extends SsoInterceptor {
    private static final Map<String, String> authMap = new ConcurrentHashMap<String, String>();
    static {
        authMap.put("huahua", "queryUserInfo");
        authMap.put("doudou", "queryUserInfo");
    }
    @Override
    public boolean preHandle(String request, String response, Object handler) {
        // 模拟获取cookie
        String ticket = request.substring(1, 8);
        // 模拟校验
        boolean success = "success" .equals(ticket);
        if (!success) {
            return false;
        }
        String userId = request.substring(9);
        String method = authMap.get(userId);
        // 模拟⽅方法校验
        return "queryUserInfo".equals(method);
    }

}
